package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcEpisodeEntity;
import com.dhcc.cdc.busi.service.ICdcEpisodeService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 患者就诊信息
 * 
 * @ClassName: CdcEpisodeController
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:20:08
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/cdcepisode")
public class CdcEpisodeController extends BaseController {

	private String PREFIX = "/backend/cdc/cdcepisode/";

	@Autowired
	private ICdcEpisodeService cdcEpisodeService;
	

    /**
     * 跳转到患者就诊信息列表首页
     */
    @RequestMapping("")
    @Permission("cdcepisode:list")
    public String index() {
        return PREFIX + "cdcepisode.html";
    }
	
    /**
     * 跳转到新增患者就诊信息
     */
    @RequestMapping("/to_add")
    @Permission("cdcepisode:add")
    public String toAdd() {
        return PREFIX + "cdcepisode_add.html";
    }
	
	/**
     * 跳转到修改患者就诊信息
     */
    @RequestMapping("/to_update/{cdcEpisodeId}")
    @Permission("cdcepisode:update")
    public String toUpdate(@PathVariable Long cdcEpisodeId, Model model) {
        CdcEpisodeEntity cdcEpisode = this.cdcEpisodeService.selectById(cdcEpisodeId);
        model.addAttribute("cdcEpisode",cdcEpisode);
        return PREFIX + "cdcepisode_edit.html";
    }

    /**
     * 获取患者就诊信息列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("cdcepisode:list")
    public Object list(@RequestParam Map<String, Object> params) {
        List<CdcEpisodeEntity> result = null;
        Page<CdcEpisodeEntity> page = new PageFactory<CdcEpisodeEntity>().defaultPage();
        if((CommonUtil.isNotEmpty(params.get("NotQuery")))&&(params.get("NotQuery").toString().equals("true"))){
            result = new ArrayList<CdcEpisodeEntity>();
        }else{
            result = this.cdcEpisodeService.page(page,params);
        }
        page.setRecords((List<CdcEpisodeEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }
    
    @RequestMapping(value = "/query")
    @ResponseBody
    @Permission("cdcepisode:list")
    public Object query(@RequestParam Map<String, Object> params) {
        List<CdcEpisodeEntity> result = new ArrayList<CdcEpisodeEntity>();
        if((CommonUtil.isNotEmpty(params.get("NotQuery")))&&(params.get("NotQuery").toString().equals("true"))){
            return result;
        }
        if(CommonUtil.isNotEmpty(params.get("EpisodeID"))){
            String EpisodeID=(String) params.get("EpisodeID");
            CdcEpisodeEntity cdcEpisode = this.cdcEpisodeService.selectById(EpisodeID);
            result.add(cdcEpisode);
            return result;
        }
        result = this.cdcEpisodeService.list(params);
        return result;
    }
    /**
     * 新增患者就诊信息
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("cdcepisode:add")
    @BussinessLog(value = "新增患者就诊信息")
    public Object add(CdcEpisodeEntity cdcEpisode) {
        if (CommonUtil.isOneEmpty(cdcEpisode)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        cdcEpisode.insert();
        return R.ok();
    }

    /**
     * 删除患者就诊信息
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("cdcepisode:delete")
    @BussinessLog(value = "删除患者就诊信息")
    public Object delete(@RequestParam Long cdcEpisodeId) {
	
        this.cdcEpisodeService.deleteById(cdcEpisodeId);

        return R.ok();
    }

    /**
     * 修改患者就诊信息
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("cdcepisode:update")
    @BussinessLog(value = "修改患者就诊信息")
    public Object update(CdcEpisodeEntity cdcEpisode) {
        if (CommonUtil.isOneEmpty(cdcEpisode)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcEpisodeEntity old = this.cdcEpisodeService.selectById(cdcEpisode.getId());

        old.setXcode(cdcEpisode.getXcode());
        old.setEpisodeNum(cdcEpisode.getEpisodeNum());
        old.setPatientCode(cdcEpisode.getPatientCode());
        old.setBusAdmTypeId(cdcEpisode.getBusAdmTypeId());
        old.setBusAdmStatusId(cdcEpisode.getBusAdmStatusId());
        old.setHealthCode(cdcEpisode.getHealthCode());
        old.setName(cdcEpisode.getName());
        old.setGender(cdcEpisode.getGender());
        old.setNationality(cdcEpisode.getNationality());
        old.setNation(cdcEpisode.getNation());
        old.setBirthdate(cdcEpisode.getBirthdate());
        old.setAge(cdcEpisode.getAge());
        old.setCardType(cdcEpisode.getCardType());
        old.setCardValue(cdcEpisode.getCardValue());
        old.setNativePlace(cdcEpisode.getNativePlace());
        old.setCompany(cdcEpisode.getCompany());
        old.setTelephone(cdcEpisode.getTelephone());
        old.setEmail(cdcEpisode.getEmail());
        old.setContactor(cdcEpisode.getContactor());
        old.setContactorPhone(cdcEpisode.getContactorPhone());
        old.setCareer(cdcEpisode.getCareer());
        old.setBloodAbo(cdcEpisode.getBloodAbo());
        old.setBloodRh(cdcEpisode.getBloodRh());
        old.setRegistNum(cdcEpisode.getRegistNum());
        old.setMrNum(cdcEpisode.getMrNum());
        old.setNativeProvince(cdcEpisode.getNativeProvince());
        old.setNativeCity(cdcEpisode.getNativeCity());
        old.setNativeCounty(cdcEpisode.getNativeCounty());
        old.setNativeTown(cdcEpisode.getNativeTown());
        old.setNativeAddress(cdcEpisode.getNativeAddress());
        old.setNowProvince(cdcEpisode.getNowProvince());
        old.setNowCity(cdcEpisode.getNowCity());
        old.setNowCounty(cdcEpisode.getNowCounty());
        old.setNowTown(cdcEpisode.getNowTown());
        old.setNowAddress(cdcEpisode.getNowAddress());
        old.setIsDeath(cdcEpisode.getIsDeath());
        old.setDeathDate(cdcEpisode.getDeathDate());
        old.setAdmNums(cdcEpisode.getAdmNums());
        old.setAdmDate(cdcEpisode.getAdmDate());
        old.setAdmLocId(cdcEpisode.getAdmLocId());
        old.setAdmLocDesc(cdcEpisode.getAdmLocDesc());
        old.setAdmWardId(cdcEpisode.getAdmWardId());
        old.setAdmWardDesc(cdcEpisode.getAdmWardDesc());
        old.setAdmRoom(cdcEpisode.getAdmRoom());
        old.setAdmBed(cdcEpisode.getAdmBed());
        old.setAdmDoctorId(cdcEpisode.getAdmDoctorId());
        old.setAdmDoctorName(cdcEpisode.getAdmDoctorName());
        old.setDishDate(cdcEpisode.getDishDate());
        old.setAdmDays(cdcEpisode.getAdmDays());
        old.setIsNewly(cdcEpisode.getIsNewly());
        old.setIsNewborn(cdcEpisode.getIsNewborn());
        old.setBornWeight(cdcEpisode.getBornWeight());
        old.setAdmWeight(cdcEpisode.getAdmWeight());
        old.setDataId(cdcEpisode.getDataId());
        old.setIsActive(cdcEpisode.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
    
}
